#!/usr/bin/perl
require "./quotamin-lib.pl";
&ReadParse();

my (@selectoption, @line, %defquota, $i, $dir, $lable, @kmgstr, $title);

$dir = $in{"checkeddir"};
$lable = $in{"checkedlable"};

#sync userdefaultquota file with mount output and voltab file
&sync_quota_mount();
#read userdefaultquota file in to a hash{"$dir"}->"sb hb sf hf"
&get_default_quota(\%defquota);

$title = &text('default_quota_title', $lable);

#check status
@line = split(/\s+/, $defquota{$dir});
if(($line[0] eq 0) && ($line[0] eq 0))
{
	$status = $text{"status_limit_no"};
}
else
{
	$status = $text{"status_limit_ok"};
}

&header($title, "", "quotadefault", 0, 1);

print "<form name=formdefaultquota action=index.cgi method=post onsubmit='return onsubmit_form();'>";

print "<table class=group border=1 cellpadding=4 cellspacing=0 width=100%>";

print "<tr class=title1><td class=group ><b>$text{'default_quota_tb_title'}</b></td></tr>";

print "<tr><td class=group><table border=0 class=mode1 cellpadding=0 cellspacing=0 width=100%>";

if($status eq $text{"status_limit_ok"})
{

	print "<tr><td width=1%><input name=limitstatus type=radio onclick='on_radio_click_nolimit();' value='nolimit'></td><td>$text{'default_quota_lable_no_limit'}</td><td></td><td></td></tr>";
	#print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_limit(\"$status\");' checked value='ok'></td><td>$text{'editquota_lable_hblock_limit'}</td><td><input name=h_input_num class=text type=text value=\"$hkmg[0]\"></td><td>";
	print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_limit(\"$status\");' checked value='ok'></td>";
	@line = split(/\s+/, $defquota{$dir});
	@kmgstr = &blocks_to_KMG_str($line[1]);
	print "<td width=18%>$text{'default_quota_lable_hblock_limit'}</td><td width=7%><input name=h_input_num size=8 class=text type=text value=\"";
	if($kmgstr[2] eq "integer")
	{
		print $kmgstr[0];
	}
	else
	{
		printf "%.2f", $kmgstr[0];
	}
	print "\"></td><td>";
}
else
{
	print "<tr><td width=1%><input name=limitstatus type=radio onclick='on_radio_click_nolimit();' checked value='nolimit'></td><td width=20%>$text{'default_quota_lable_no_limit'}</td><td width=%7></td><td></td></tr>";
	#print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_limit(\"$status\");' value='ok'></td><td>$text{'editquota_lable_hblock_limit'}</td><td><input name=h_input_num class=text type=text disabled=true value='$status'></td><td>";
	print "<tr><td><input name=limitstatus type=radio onclick='on_radio_click_limit(\"$status\");' value='ok'></td><td>$text{'default_quota_lable_hblock_limit'}</td><td width=7%><input name=h_input_num class=disabletext type=text disabled=true value='$status'></td><td>";
}


@selectoption = ("<option value='KB'>KB", "<option value='MB'>MB", "<option value='GB'>GB");

print "<select name=h_unit size=1>";

if($kmgstr[1] eq "KB")
{
	$selectoption[0] = "<option selected value='KB'>KB";
}
if($kmgstr[1] eq "MB")
{
	$selectoption[1] = "<option selected value='MB'>MB";
}
if($kmgstr[1] eq "GB")
{
	$selectoption[2] = "<option selected value='GB'>GB";
}

print @selectoption;

print "</select>";
print "</td></tr>";

if($status eq $text{"status_limit_ok"})
{
	print "<tr><td></td>";
	@line = split(/\s+/, $defquota{$dir});
	@kmgstr = &blocks_to_KMG_str($line[0]);
	print "<td width=18%>$text{'default_quota_lable_sblock_limit'}</td><td width=7%><input name=s_input_num size=8 class=text type=text value=\"";
	if($kmgstr[2] eq "integer")
	{
		print $kmgstr[0];
	}
	else
	{
		printf "%.2f", $kmgstr[0];
	}
	print "\"></td><td>";
}
else
{
	print "<tr><td></td><td>$text{'default_quota_lable_sblock_limit'}</td><td><input name=s_input_num class=disabletext type=text disabled=true value=\"$status\"></td><td>";
}


@line = split(/\s+/, $defquota{$dir});
@kmgstr = &blocks_to_KMG_str($line[0]);
@selectoption = ("<option value='KB'>KB", "<option value='MB'>MB", "<option value='GB'>GB");

print "<select name=s_unit size=1>";

if($kmgstr[1] eq "KB")
{
	$selectoption[0] = "<option selected value='KB'>KB";
}
if($kmgstr[1] eq "MB")
{
	$selectoption[1] = "<option selected value='MB'>MB";
}
if($kmgstr[1] eq "GB")
{
	$selectoption[2] = "<option selected value='GB'>GB";
}

print @selectoption;

print "</select>";
print "</td></tr>";


print "</table>";
print "</td></tr>";

print "</table>";

print "<table class=mode1 cellpadding=4 cellspacing=10>";

print "<tr><td><input name=submit_update class=button1 type=submit onclick=\'return on_submit_ok_click();\' value=\"$text{'default_quota_submit_update'}\"></td>";
print "<td><input name=submit_cancel class=button1 type=submit onclick=\'return on_submit_cancel_click();\' value=\"$text{'default_quota_submit_cancel'}\"></td></tr>";

print "</table>";

print "<input name=checkeddir type=hidden value=\"$dir\">";
print "<input name=lable type=hidden value=\"$lable\">";

print "</form>";

print <<EOF;
<script>

function onsubmit_form()
{
        document.forms[0].submit_update.disabled = true;
        document.forms[0].submit_cancel.disabled = true;
}

function on_radio_click_nolimit()
{
	document.forms[0].h_input_num.disabled = true;
	document.forms[0].s_input_num.disabled = true;
	document.forms[0].h_input_num.style.backgroundColor = "#d4d0c8";
	document.forms[0].s_input_num.style.backgroundColor = "#d4d0c8";
}

function on_radio_click_limit(status)
{
	document.forms[0].h_input_num.disabled = false;
	document.forms[0].s_input_num.disabled = false;
	document.forms[0].h_input_num.style.backgroundColor = "#ffffff";
	document.forms[0].s_input_num.style.backgroundColor = "#ffffff";
	if(document.forms[0].h_input_num.value == status)
	{
		document.forms[0].h_input_num.value = 4;
	}
	if(document.forms[0].s_input_num.value == status)
	{
		document.forms[0].s_input_num.value = 4;
	}
}

function on_submit_ok_click()
{
	document.forms[0].action = "update_usrdefquota.cgi";
}

function on_submit_cancel_click()
{
	document.forms[0].action = "index.cgi";
}

</script>
EOF

&footer("/quotamin/", $text{'index'});
